@extends('admin.layout.index')
@section('content')
	<div class="portlet box blue">

							<div class="portlet-title">

								<div class="caption"><i class="icon-reorder"></i>添加广告信息</div>

								<div class="tools">

									<a href="javascript:;" class="collapse"></a>

									<a href="#portlet-config" data-toggle="modal" class="config"></a>

									<a href="javascript:;" class="reload"></a>

									<a href="javascript:;" class="remove"></a>

								</div>

							</div>
			
							<div class="portlet-body form">

								<!-- BEGIN FORM-->
								
								<form action="/admin/ad" id="ad_form" class="form-horizontal" method="post" enctype="multipart/form-data">
									{{ csrf_field() }}
									<label class="control-label">图片名称</label>
									<div class="span7">

									<!-- The fileinput-button span is used to style the file input field as button -->
										<td>
				                            <input type="text" name="pic" id="pic">
				                            {{--文件上传插件--}}
				                            <input id="file_upload" name="file_upload" type="file" multiple="true">

				                            <p><img id="img1" alt="上传后显示图片"  style="max-width:350px;max-height:100px;" /></p>

		                       		 	</td>					
																		
									</div>

									<br><br>
									<br><br>
									<br><br>
									<br><br>
									

									<div class="control-group">

										<label class="control-label">Url</label>

										<div class="controls">

										<input type="text" class="span6 m-wrap" name="url" value="">

										

										</div>

									</div>
									<div class="control-group">

										<label class="control-label">排序</label>

										<div class="controls">

										<input type="text" class="span6 m-wrap" name="order" value="" style="width:100px;">

										

										</div>

									</div>
									<div class="control-group">

										<label class="control-label">描述</label>

										<div class="controls">

										<input type="text" class="span6 m-wrap" name="description" value="">

										

										</div>

									</div>

									

									<div class="form-actions">

										<button type="submit" class="btn blue">添加</button>

									                       

									</div>

								</form>

								<!-- END FORM-->       

							</div>

						</div>	
	 <script type="text/javascript">
        $(function () {
            $("#file_upload").change(function () {
                uploadImage();
            });
        });

        function uploadImage() {
	//                            判断是否有选择上传文件
            var imgPath = $("#file_upload").val();
            if (imgPath == "") {
                alert("请选择上传图片！");
                return;
            }
            //判断上传文件的后缀名
            var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1);
            if (strExtension != 'jpg' && strExtension != 'gif'
                && strExtension != 'png' && strExtension != 'bmp') {
                alert("请选择图片文件");
                return;
            }
//                            var myform = document.getElementById('art_from');
            var formData = new FormData($('#ad_form')[0]);
            {{--formData.append('_token', '{{csrf_token()}}');--}}
                                        {{--console.log(formData);--}}
            $.ajax({
                type: "POST",
                url: "/admin/ad_upload",
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {
                                   // console.log(data);
                                   // alert("上传成功");
//                    $('#img1').attr('src','http://ovf9o4wws.bkt.clouddn.com/'+data);
//                    http://project187.oss-cn-shanghai.aliyuncs.com/uploads/201708290957357759.jpg
                   $('#img1').attr('src','/'+data);
                    $('#pic').val(data);

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("上传失败，请检查网络后重试");
                }
            });
        }

    </script>			
@endsection